<?php

namespace app\admin\model;

use think\Model;

class Questionbank extends Model
{
    // 表名
    protected $name = 'questionbank';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'class_text'
    ];
    

    
    public function getClassList()
    {
        return ['单选题' => __('单选题'),'多选题' => __('多选题')];
    }     


    public function getClassTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['class']) ? $data['class'] : '');
        $list = $this->getClassList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function subject()
    {
        return $this->belongsTo('Subject', 'subject_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function package()
    {
        return $this->belongsTo('Package', 'package_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
